/*
 *  EventLib
 *  qComponent.h
 *
 *	Copyright (c) 2001, AVS
 *	All rights reserved.
 *
 *	Redistribution and use in source and binary forms, with or without
 *	modification, are permitted provided that the following conditions are met:
 *	1.	Redistributions of source code must retain the above copyright
 *		notice, this list of conditions and the following disclaimer.
 *	2.	Redistributions in binary form must reproduce the above copyright
 *		notice, this list of conditions and the following disclaimer in the
 *		documentation and/or other materials provided with the distribution.
 *	3.	All advertising materials mentioning features or use of this software
 *		must display the following acknowledgement:
 *		This product includes software developed by the AVS.
 *	4.	Neither the name of the AVS nor the
 *		names of its contributors may be used to endorse or promote products
 *		derived from this software without specific prior written permission.
 *
 *	THIS SOFTWARE IS PROVIDED BY AVS ''AS IS'' AND ANY
 *	EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 *	WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 *	DISCLAIMED. IN NO EVENT SHALL AVS BE LIABLE FOR ANY
 *	DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 *	(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 *	ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *	(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 *	SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


#ifndef _qComponent_h
#define _qComponent_h

#include <map>
#include <string>

#include "ScriptLib.h"

template<typename T>
T caster(void *data)
{
	return (T)data;
}

class qComponent : public iScriptable<qComponent>
{
public:
	qComponent();
	qComponent(qComponent *root);
	~qComponent();
	
	
	qComponent		*getRoot();
	qComponent		*getComp(std::string comp);
	bool			addComp(std::string comp, qComponent *it);
	
	void becomes(qComponent *ptr)
	{
		*this = (qComponent*)(ptr);
	}
	
	void REGISTER_SCRIPTABLES(qScriptEngine *engine)
	{
		//engine->RegisterScriptable<qEntity>();
		REGISTER_CLASS(engine, "qComponent", qComponent);
		
		
		REGISTER_METHOD(engine, "qComponent", qComponent, "void become(qComponent &ptr)", becomes);
	//	engine->getEngine()->RegisterGlobalFunction("T caster<T>(void*)", asFUNCTION(caster), asCALL_CDECL);
		//REGISTER_METHOD(engine, "qComponent", qComponent, "T cast()", cast);
		//engine->getEngine()->RegisterObjectBehaviour(<#const char *obj#>, <#asEBehaviours behaviour#>, <#const char *declaration#>, <#const asSFuncPtr funcPointer#>, <#asDWORD callConv#>)
	//	REGISTER_METHOD(engine, "qComponent", qComponent, "qEntity &cast()", cast);
		//REGISTER_METHOD(engine, "qComponent", qComponent, "qEntity cast()", cast);
		
		/*REGISTER_METHOD(engine, "qEntity", qEntity, "void print()", print);
		
		REGISTER_METHOD(engine, "qEntity", qEntity, "float getX()", getX);
		REGISTER_METHOD(engine, "qEntity", qEntity, "float getY()", getY);
		REGISTER_METHOD(engine, "qEntity", qEntity, "void setX(float _x)", setX);
		REGISTER_METHOD(engine, "qEntity", qEntity, "void setY(float _y)", setY);*/
		//REGISTER_METHOD(engine, "err", err, "string &get_err()", get_err);
		
		//REGISTER_GLOBAL_PROPERTY(engine, "float mx", &this->x);
		//REGISTER_GLOBAL_PROPERTY(engine, "float mx", &this->y);
	}
	
private:	
	qComponent								*root;
	std::map<std::string, qComponent*>		comps;
};

extern int GI;

#endif